package com.rongc.client.freight.business.mine.view.activity;

import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.UniApplication;
import com.rongc.client.freight.base.BaseActivity;
import com.rongc.client.freight.base.model.BaseDic;
import com.rongc.client.freight.base.view.activity.AuthActivity;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Bruce on 2017/7/19.
 */
public class AuthHostActivity extends BaseActivity implements View.OnClickListener{
    @Bind(R.id.tv_owner_tip)
    TextView mTvOwner;
    @Bind(R.id.tv_drivier_tip)
    TextView mTvDrivier;
    @Bind(R.id.tv_tip)
    TextView mTvTip;

    @Override
    public void onAuth() {
        if(UniApplication.getInstance().isAuth()) {
            ActivityUtils.toast("您已认证");
            return;
        }
        if(BaseDic.AuthStatus.AUTH_ING_STATUS.equals(UniApplication.getInstance().getUserInfo().getAuthStatus())) {
            ActivityUtils.toast("您的认证资料正在审核中，请耐心等待");
            return;
        }
        ActivityUtils.startActivity(this, AuthActivity.class);
    }

    @OnClick({R.id.lyt_driving,R.id.lyt_shipper,R.id.tv_tip})
    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.lyt_driving:
                if(UniApplication.getInstance().getType().equals(BaseDic.IdentityType.DRIVING_TYPE)) {
                    if(UniApplication.getInstance().isAuth()) {
                        ActivityUtils.toast("您已认证");
                        return;
                    }
                    doAuth();

                }else
                    ActivityUtils.toast("货主无法进行司机认证");

                break;
            case R.id.lyt_shipper:
                if(UniApplication.getInstance().getType().equals(BaseDic.IdentityType.OWNER_TYPE)) {
                    if(UniApplication.getInstance().isAuth()) {
                        ActivityUtils.toast("您已认证");
                        return;
                    }
                    doAuth();

                }else
                    ActivityUtils.toast("司机无法进行货主认证");
                break;
            case R.id.tv_tip:
                ActivityUtils.callToContact(this);
                break;
        }
    }

    @Override
    public void initView() {
        initToolbar(R.string.mine_auth_title);
        if(UniApplication.getInstance().isAuth()) {
            switch (UniApplication.getInstance().getType()){
                case BaseDic.IdentityType.DRIVING_TYPE:
                    mTvDrivier.setText("已认证");
                    mTvDrivier.setTextColor(getResources().getColor(R.color.universal_text_link));
                    break;
                case BaseDic.IdentityType.OWNER_TYPE:
                    mTvOwner.setText("已认证");
                    mTvOwner.setTextColor(getResources().getColor(R.color.universal_text_link));
                    break;
            }
        }
        mTvTip.setText(Html.fromHtml(getResources().getString(R.string.auth_host_tip)));
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_auth_host;
    }
}
